@echo off
set REDIS_DIR=D:\code\setting\Redis-x64-3.0.504
set ROCKETMQ_DIR=D:\code\setting\rocketmq-5.2.0\bin

:CheckRedis
echo Checking if Redis is already running...
tasklist /FI "IMAGENAME eq redis-server.exe" | findstr /C:"redis-server.exe" >nul
if %errorlevel%==0 (
    echo Redis is already running.
) else (
    echo Starting Redis...
    start "" "%REDIS_DIR%\redis-server.exe"
    timeout 1 >nul
)

:CheckRocketMQNameserver
echo Checking if RocketMQ Nameserver is already running...
tasklist /FI "IMAGENAME eq mqnamesrv.cmd" | findstr /C:"mqnamesrv.cmd" >nul
if %errorlevel%==0 (
    echo RocketMQ Nameserver is already running.
) else (
    echo Starting RocketMQ Nameserver...
    start "" "%ROCKETMQ_DIR%\mqnamesrv.cmd"
    timeout 1 >nul
)

:CheckRocketMQBroker
echo Checking if RocketMQ Broker is already running...
tasklist /FI "IMAGENAME eq mqbroker.cmd" | findstr /C:"mqbroker.cmd" >nul
if %errorlevel%==0 (
    echo RocketMQ Broker is already running.
) else (
    echo Starting RocketMQ Broker...
    start "" "%ROCKETMQ_DIR%\mqbroker.cmd" -n localhost:9876 autoCreateTopicEnable=true
    timeout 1 >nul
)

echo All services started. Press any key to exit.
exit